import React, { Dispatch, SetStateAction } from 'react';
import './Loading.scss';
import { openAni } from '../App/App';
import Animation from './Animation/Animation';

interface LoadingProps {
    setOpenAni: Dispatch<SetStateAction<openAni>>
    openAni: openAni
}

function createLoadingAnimate(props: LoadingProps) {
  return () => {
    props.openAni?.gameOver
      ? props.setOpenAni({ gameShow: true })
      : props.openAni.loadingOver = true;
  };
}

const Loading: React.FC<LoadingProps> = (props) => {
  React.useEffect(() => {
    console.log('componentDidMount');
    return function cleanup() {
      console.log('组件被卸载componentWillUnmount');
    };
  }, []);
  console.log(222222);
  return (
    <div className={'loading-box'}>
      <Animation loadingAnimate={createLoadingAnimate(props)}/>
    </div>
  );
};

export default Loading;
